package com.swmutil.swmutil.sqlite;

/**
 * @author 师文明
 * @data 2024/10/21 下午5:22
 **/

import com.swmutil.swmutil.pojo.All_Page;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author cpf
 * @Date 2023/9/2
 */

public class AllPageSql {

    //TODO 查询所有数据
    private static final String SQL_queryList = "SELECT * FROM all_page;";

    //TODO 查询
    public static List<All_Page> queryPagesList() {
        List<All_Page> pages = new ArrayList<All_Page>();

        try {
            ResultSet rs = ProjectStaticManager.statement.executeQuery(SQL_queryList);
            while (rs.next()) {
                All_Page page = new All_Page(rs.getInt("id"), rs.getString("page_name"));
                pages.add(page);
            }
            rs.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return pages;
    }

    public static void insertPage() {
        // 插入数据 id是自增，因此新增的时候可以不管id
        String insertPageSQL = "INSERT INTO all_page (page_name) VALUES ('割台')";
        try {
            int page = ProjectStaticManager.statement.executeUpdate(insertPageSQL);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) {
        insertPage();
    }
}

